input1='6 2'
input2='aaaaaa'
input3='4 2'
input4='aaaa\naa'


[n,m]=list(map(int,input1.split()))
data=input2
requir=list(map(int,input3.split()))

need=list(map(str,input4.split('\n')))
memo = [1] * (len(data)+1)
res = []
print(need)
def judge(data,temp,pos):
    num=len(res)
    if pos==len(data):
        res.append(''.join(temp))
        return
    for i in range(pos,n+1):
        if memo[i] and data[pos:i] in need:
            temp.append(data[pos:i])
            judge(data,temp,i)
            temp.pop()
    memo[pos]=1 if len(res)>num else 0

judge(data,[],0)
print(res)



